//Manage Member
	function allStdProfile()  
		{
			$.get('page/admin-login-studentprofile.php',function(data)
				{
					showStudentProfile();
					$('#adminInformation').html(data);
				});
		}

	function allTchProfile()  
		{
			$.get('page/admin-login-teacherprofile.php',function(data)
				{
					showTeacherProfile();
					$('#adminInformation').html(data);
				});
		}
	
	function showStudentProfile() 
		{
			$('#informationMember').html('Loading...');
				$.getJSON('function/json-student.php',function(data)
			{
			$('#informationMember').html('');
			$.each(data,function(key,val){
			$('#informationMember').html(
			$('#informationMember').html()
			+'<table>'
			+'<td width=40>'
			+'<font color="white" size=4>'
			+val['student_id']
			+'</font></td>'
			+'<td width=150>'
			+'<font color="white" size=4>'
			+val['student_firstname']
			+'</font></td>'
			+'<td width="150">'
			+'<font color="white" size=4>'
			+val['student_lastname']
			+'</font>'
			+'<td width=150>'
			+'<font color="white" size=4>'
			+val['student_ncuid']
			+'</font>'
			+'</td><td width="200">'
			+'<font color="white" size=4>'
			+val['student_email']
			+'</font></td>'
			+'<td width=150>'
			+'<font color="white" size=4>'
			+val['student_tel']
			+'</font></td>'
			+'<td width=100>'
			+'<font color="white" size=4>'
			+val['student_faculty']
			+'</font>'
			+'</td><td width=50> <img id="delimg'+val['student_id']+'" src="Picture-project/PNGfile/del-icon.png" style="cursor:pointer;" onclick="delStudent('+val['student_id']+');">'
			+'</td></tr></table>'
			+'<img src="Picture-project/PNGfile/Text-line.png" width=1000>'
			);
			});
			});
		}

	function showTeacherProfile() 
		{
			$('#informationMember').html('Loading...');
				$.getJSON('function/json-teacher.php',function(data)
			{
			$('#informationMember').html('');
			$.each(data,function(key,val){
			$('#informationMember').html(
			$('#informationMember').html()
			+'<table>'
			+'<td width=40>'
			+'<font color="white" size=4>'
			+val['teacher_id']
			+'</font></td>'
			+'<td width=150>'
			+'<font color="white" size=4>'
			+val['teacher_firstname']
			+'</font></td>'
			+'<td width="150">'
			+'<font color="white" size=4>'
			+val['teacher_lastname']
			+'</font>'
			+'<td width=150>'
			+'<font color="white" size=4>'
			+val['teacher_ncuid']
			+'</font>'
			+'</td><td width="200">'
			+'<font color="white" size=4>'
			+val['teacher_email']
			+'</font></td>'
			+'<td width=150>'
			+'<font color="white" size=4>'
			+val['teacher_tel']
			+'</font></td>'
			+'<td width=100>'
			+'<font color="white" size=4>'
			+val['teacher_faculty']
			+'</font>'
			+'</td><td width=50> <img id="delimg'+val['teacher_id']+'" src="Picture-project/PNGfile/del-icon.png" style="cursor:pointer;" onclick="delTeacher('+val['teacher_id']+');">'
			+'</td></tr></table>'
			+'<img src="Picture-project/PNGfile/Text-line.png" width=1000>'
			);
			});
			});
		}

	function delStudent(student_id)
		{	
			if (confirm("Do you want to delete ?") )
			{
				$.post('function/delete.php',{'student_id': student_id} , function(data)//ใส่{'id':id} เข้าไปเพื่อรับ id จาก delete.php
				{
				alert ("Delete Complete");
				showStudentProfile();
				});
			}

			else
			{
				showStudentProfile();
			}
		}

	function delTeacher(teacher_id)
		{	
			if (confirm("Do you want to delete ?") )
			{
				$.post('function/delete.php',{'teacher_id': teacher_id} , function(data)//ใส่{'id':id} เข้าไปเพื่อรับ id จาก delete.php
				{
				alert ("Delete Complete");
				showTeacherProfile();
				});
			}

			else
			{
				showTeacherProfile();
			}
		}

//Manage Subject
	function showSubject()  
		{
			$.get('page/admin-login-addsubject.php',function(data)
				{
					getTchName(); 
					$('#adminInformation').html(data);
				});
		}

	function getTchName() 
		{
			$.getJSON('function/json-teacher.php',function(data) 
			{
				$('#subjectteacher').html('<option></option>');
				$.each(data,function(key, val) 
				{
					$('#subjectteacher').html(
					$('#subjectteacher').html()
					+ '<option id="'+val['teacher_id']+'">'+val['teacher_firstname']+'</option>'
					);
				});
			});
		}

	function addSubject()//เป็นปุ่มการทำงานของ submit
		{	
			if($('#subjectid').val()=='')
			{
				alert("Please insert Subject's ID");
			}
			else if($('#subjectname').val()=='')
			{
				alert("Please insert Subject's Name");
			}
			else if($('#subjectteacher').val()=='')
			{
				alert("Please insert Teacher's name to teach this subject");
			}	
			else{
			$.post('function/addsubject.php',{
				'subjectid' : $('#subjectid').val(),
				'subjectname' : $('#subjectname').val(),
				'subjectteacher' : $('#subjectteacher').val(),
				'subjectfaculty' : $('#subjectfaculty').val()},
				function(data)//ทำการรีบข้อมูลมาจาก response.php โดยทำการรับข้อมูลตามที่ได้กำหนดไว้
			{	
				alert("Add Subject Successful");});
				afterRegister();
				
			}
		}

	function showMngSubject()  
		{
			$.get('page/admin-login-mngsubject.php',function(data)
				{
					 mngSubject();
					$('#adminInformation').html(data);
				});
		}

	function mngSubject() 
		{
			$('#informationMain').html('Loading...');
				$.getJSON('function/json-subject.php',function(data)
			{
			$('#informationMain').html('');
			$.each(data,function(key,val){
			$('#informationMain').html(
			$('#informationMain').html()
			+'<table>'
			+'<td width=40>'
			+'<font color="white" size=4>'
			+val['sub_id']
			+'</font></td>'
			+'<td width=150>'
			+'<font color="white" size=4>'
			+'<span id="value'+val['sub_id']+'">'+val['subject_id']+'</span>'
			+'</font></td>'
			+'<td width="250">'
			+'<font color="white" size=4>'
			+'<span id="value2'+val['sub_id']+'">'+val['subject_name']+'</span>'
			+'</font>'
			+'<td width=250>'
			+'<font color="white" size=4>'
			+'<span id="value3'+val['sub_id']+'">'+val['subject_teacher']+'</span>'
			+'</font>'
			+'</td><td width="200">'
			+'<font color="white" size=4>'
			+'<span id="value4'+val['sub_id']+'">'+val['subject_faculty']+'</span>'
			+'</font></td>'
			+'</td><td width=50> <img id="editimg'+val['sub_id']+'" src="Picture-project/PNGfile/edit-icon.png" style="cursor:pointer;" onclick="editSubject('+val['sub_id']+');">'
			+'</td><td width=50> <img id="delimg'+val['sub_id']+'" src="Picture-project/PNGfile/del-icon.png" style="cursor:pointer;" onclick="delSubject('+val['sub_id']+');">'
			+'</td></tr></table>'
			+'<img src="Picture-project/PNGfile/Text-line.png" width=1000>'
			);
			});
			});
		}

	function delSubject(sub_id)
		{	
			if (confirm("Do you want to delete ?") )
			{
				$.post('function/delete.php',{'sub_id': sub_id} , function(data)//ใส่{'id':id} เข้าไปเพื่อรับ id จาก delete.php
				{
					mngSubject();
				});
			}

			else
			{
				mngSubject();
			}
		}

	function editSubject(sub_id)
		{
			$('#editimg'+sub_id).hide();
			$('#value'+sub_id).html('<input id="txtvalue'+sub_id+'" type="text" onkeydown = "updateSubject('+sub_id+',event);" value="'+$('#value'+sub_id).html()+'">');
			$('#value2'+sub_id).html('<input id="txtvalue2'+sub_id+'" type="text" onkeydown = "updateSubject('+sub_id+',event);" value="'+$('#value2'+sub_id).html()+'">');//value หลัง event เป็นตัวแปรไม่ใช่ ID
			$('#value3'+sub_id).html('<input id="txtvalue3'+sub_id+'" type="text" onkeydown = "updateSubject('+sub_id+',event);" value="'+$('#value3'+sub_id).html()+'">');
			$('#value4'+sub_id).html('<input id="txtvalue4'+sub_id+'" type="text" onkeydown = "updateSubject('+sub_id+',event);" value="'+$('#value4'+sub_id).html()+'">');		
		}

	function updateSubject(sub_id,event)
		{


			if(event.keyCode==13)//เมื่อกด Enter 
			{
				if($('#txtvalue'+sub_id+'').val()=='')
				{
				event.preventDefault();
				alert('Please insert subjects id');
				}
				else if($('#txtvalue2'+sub_id).val()=='')
				{
				event.preventDefault();
				alert('Please insert subjects name');
				}
				else if($('#txtvalue3'+sub_id).val()=='')
				{
				event.preventDefault();
				alert('Please insert teachers subject');
				}
				else if($('#txtvalue4'+sub_id).val()=='')
				{
				event.preventDefault();
				alert('Please insert facultys subject');
				}
				else if($('#txtvalue'+sub_id).val()==(event.keyCode==32))
				{
				event.preventDefault();
				alert('Please insert subjects id');
				}
				else if($('#txtvalue2'+sub_id).val()==(event.keyCode==32))
				{
				event.preventDefault();
				alert('Please insert subjects name');
				}
				else if($('#txtvalue3'+sub_id).val()==(event.keyCode==32))
				{
				event.preventDefault();
				alert('Please insert teachers subject');
				}
				else if($('#txtvalue4'+sub_id).val()==(event.keyCode==32))
				{
				event.preventDefault();
				alert('Please insert facultys subject');
				}
				else
				{
					$('#editimg'+sub_id).show();
					$.post('function/update.php',
					{
						'subject_id' : $('#txtvalue'+sub_id).val(), 'subject_name' : $('#txtvalue2'+sub_id).val() , 'subject_teacher' : $('#txtvalue3'+sub_id).val(),'subject_faculty' : $('#txtvalue4'+sub_id).val() , 'sub_id' : sub_id
					},function(data)
					{
						$('#value'+sub_id).html($('#txtvalue'+sub_id).val());
						$('#value2'+sub_id).html($('#txtvalue2'+sub_id).val());
						$('#value3'+sub_id).html($('#txtvalue3'+sub_id).val());
						$('#value4'+sub_id).html($('#txtvalue4'+sub_id).val());
					});
				}
				mngSubject();
			}
		}